/**
 * Created by Jacky
 *
 * brief :
 */

define('ssq/main', function(require){
    require('KG');
    window.template = require('artTemplate');

    var Helper = require('ssq/Helper');

    var F = {
        getTableAView : function(ssq){
            var Table_A = require('ssq/view/Table_A');
            var ta = new Table_A(ssq);

            return ta.getElement();
        },

        getTableBView : function(ssq){
            var Table_B = require('ssq/view/Table_B');
            var tb = new Table_B(ssq);

            return tb.getElement();
        },

        getSingleListAView : function(ssq){
            var View = require('ssq/view/SingleList_A');
            var obj = new View(ssq);

            return obj;
        },

        eachTest : function(st){
            var html = '';
            html += '<p>'+st.opentime+' | '+st.id+' | '+st.hong.join(',')+' | '+st.lan+'</p>'
            html += '<em>'+Helper.Kill.getAllByLast(st)+'</em>';
            html += '<b>'+st.ac+'</b>';
            return html;
        }
    };

    // tpl/ssq/index.html
    var startIndex = function(){
        var html = '',
            boxA = $('#tableA'),
            boxB = $('#tableB');
        $.getJSON('/api/ssq', function(json){
            KG.each(json, function(index, item){
                var ssq = Helper.Factory.get(item);
                html += F.eachTest(ssq);

                var table_A_elem = F.getTableAView(ssq);
                boxA.append(table_A_elem);

                var table_B_elem = F.getTableBView(ssq);
                boxB.append(table_B_elem);
            });


        });
    };

    // tpl/ssq/SingleList_A.html
    var startSingleListA = function(){
        var box = $('#SingleList-A');
        $.getJSON('/api/ssq', function(json){
            json.reverse();
            KG.each(json, function(index, item){
                var ssq = Helper.Factory.get(item);

                var listview = F.getSingleListAView(ssq);

                if(index < 1){
                    box.append(listview.getTitleElement());
                }

                box.append(listview.getElement());

            });


        });
    };


    return {
        init : startIndex,
        startSingleListA : startSingleListA
    };
});














